<?php

namespace app\model;

use think\Model;
use think\Cache;
use think\Db;
class Company extends Model{

    protected $table = 'mm_company';
    
   
    /**
     * 获取下拉公司列表
     *
     * @param [type] $pid
     * @return void
     */
    public static function getCompany($cid = 0){

        $list = Company::select();
        $html = "<select id='cid' class='form-control m-b' name='company' onchange=getPosition()>";
        foreach($list as $k => $v){
            $selected = "";
            if($v['id'] == $cid){
                $selected = 'selected';
            }
            $html .= '<option '.$selected.' value='.$v['id'].'>'.$v['company_name'].'</option>';
        }
        $html .= "</select>";
        return $html;
    }

    /**
     * 添加/编辑职务
     * @param [type] $data
     * @return void
     */
    public static function editCompany($data){
        $Aes = new \Aes();
        Db::startTrans();
        try {
            if(!empty($data['id'])){//更新
                Company::where("id",$data['id'])->update(array(
                    "company_name" =>trim($data['company_name']),
                 ));
              
            }else{//新增账号
                Company::insertGetId(array(
                    "company_name" =>trim($data['company_name']),
                    "create_time"=> date('Y-m-d H:i:s',time())
                ));
            }
            // 提交事务
            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
            return $e->getMessage();
        }
        return true; 
   }


}




    





?>